package cn.gjxblog.proxy.spring.utils;

import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

/**
 * TODO...
 *
 * @Author guojiaxun
 * @Date 2019/12/30 18:09
 */
public class TestContext {
	public static HelloService getProxy(Object targetObj){
		ProxyFactory proxyFactory = new ProxyFactory();
		proxyFactory.setTarget(targetObj);
		proxyFactory.addAdvice((MethodBeforeAdvice) (method, args1, target) -> {
			System.out.println("方法之前执行了~~~");
		});

		HelloService helloService = (HelloService) proxyFactory.getProxy();
		helloService.hello();
		System.out.println(helloService.getClass().getName());//com.fsx.service.HelloServiceImpl$$EnhancerBySpringCGLIB$$9b28670f
		return helloService;
	}
}
